package com.zbkj.service.service.project.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.zbkj.common.model.project.EstimateAi;
import com.zbkj.service.dao.project.EstimateAiMapper;
import com.zbkj.service.service.project.EstimateAiService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 项目估算ai需要填写内容表 服务实现类
 * </p>
 *
 * @author 
 * @since 2024-07-14
 */
@Service
public class EstimateAiServiceImpl extends ServiceImpl<EstimateAiMapper, EstimateAi> implements EstimateAiService {

    @Override
    public boolean delByProjectId(Long projectId) {
        if(Objects.isNull(projectId) || projectId.longValue() <= 0) {
            return false;
        }
        LambdaUpdateWrapper<EstimateAi> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.set(EstimateAi::getDeleteFlag,1)
                .eq(EstimateAi::getDeleteFlag,0)
                .eq(EstimateAi::getProjectId, projectId);
        return this.update(updateWrapper);
    }

    @Override
    public List<EstimateAi> getAiContentList(Long projectId) {
        if(Objects.isNull(projectId) || projectId.longValue() <= 0) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<EstimateAi> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EstimateAi::getDeleteFlag,0)
                .eq(EstimateAi::getProjectId, projectId);
        queryWrapper.orderByAsc(EstimateAi::getTitleSort,EstimateAi::getSortNum);
        return this.list(queryWrapper);
    }
}
